﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
namespace ERP.Classes
{
    public class cs_erp_hoadonInfo
    {
        private int _id_hd;
        private int _id_ban;
        private DateTime _ngayban;
        private int _nguoiban;
        private string _ghichu;
        private int _trangthai;
        private int _ketkho;
        private double _tongtien;
        private double _khuyenmai;
        private double _conlai;
        private double _datra;
        private double _conno;
        private int _id_kh;
        private DateTime _ngaygiaoviec;
        private int _nguoinhanviec;
        private DateTime _ngayhoanthanh;
        private DateTime _ngayhentra;
        private int _nguoigiaoviec;
        private int _nguoigiaohang;
        private DateTime _ngaygiaohang;
        private int _khoxuat;
        private int _khonhap;
        private DateTime _ngaythu;
        private string _sohd;
        private bool _tructiep;

        public cs_erp_hoadonInfo()
        {
            this._id_hd = 0;
            this._id_ban = 0;
            this._ngayban = Convert.ToDateTime("01/01/9999");
            this._nguoiban = 0;
            this._ghichu = " ";
            this._trangthai = 1;
            this._ketkho = 0;
            this._tongtien = 0;
            this._khuyenmai = 0;
            this._conlai = 0;
            this._datra = 0;
            this._conno = 0;
            this._id_kh = 0;
            this._ngaygiaoviec = Convert.ToDateTime("01/01/9999");
            this._nguoinhanviec = 0;
            this._ngayhoanthanh = Convert.ToDateTime("01/01/9999");
            this._ngayhentra = Convert.ToDateTime("01/01/9999");
            this._nguoigiaoviec = 0;
            this._nguoigiaohang = 0;
            this._ngaygiaohang = Convert.ToDateTime("01/01/9999");
            this._khoxuat = 0;
            this._khonhap = 0;
            this._ngaythu = Convert.ToDateTime("01/01/9999");
            this._sohd = " ";
            this._tructiep = false;
        }
        public int id_hd
        {
            get
            {
                return this._id_hd;
            }
            set
            {
                this._id_hd = value;
            }
        }
        public int id_ban
        {
            get
            {
                return this._id_ban;
            }
            set
            {
                this._id_ban = value;
            }
        }
        public DateTime ngayban
        {
            get
            {
                return this._ngayban;
            }
            set
            {
                this._ngayban = value;
            }
        }
        public int nguoiban
        {
            get
            {
                return this._nguoiban;
            }
            set
            {
                this._nguoiban = value;
            }
        }
        public string ghichu
        {
            get
            {
                return this._ghichu;
            }
            set
            {
                this._ghichu = value;
            }
        }
        public int trangthai
        {
            get
            {
                return this._trangthai;
            }
            set
            {
                this._trangthai = value;
            }
        }
        public int ketkho
        {
            get
            {
                return this._ketkho;
            }
            set
            {
                this._ketkho = value;
            }
        }
        public double tongtien
        {
            get
            {
                return this._tongtien;
            }
            set
            {
                this._tongtien = value;
            }
        }
        public double khuyenmai
        {
            get
            {
                return this._khuyenmai;
            }
            set
            {
                this._khuyenmai = value;
            }
        }
        public double conlai
        {
            get
            {
                return this._conlai;
            }
            set
            {
                this._conlai = value;
            }
        }
        public double datra
        {
            get
            {
                return this._datra;
            }
            set
            {
                this._datra = value;
            }
        }
        public double conno
        {
            get
            {
                return this._conno;
            }
            set
            {
                this._conno = value;
            }
        }
        public int id_kh
        {
            get
            {
                return this._id_kh;
            }
            set
            {
                this._id_kh = value;
            }
        }
        public DateTime ngaygiaoviec
        {
            get
            {
                return this._ngaygiaoviec;
            }
            set
            {
                this._ngaygiaoviec = value;
            }
        }
        public int nguoinhanviec
        {
            get
            {
                return this._nguoinhanviec;
            }
            set
            {
                this._nguoinhanviec = value;
            }
        }
        public DateTime ngayhoanthanh
        {
            get
            {
                return this._ngayhoanthanh;
            }
            set
            {
                this._ngayhoanthanh = value;
            }
        }
        public DateTime ngayhentra
        {
            get
            {
                return this._ngayhentra;
            }
            set
            {
                this._ngayhentra = value;
            }
        }
        public int nguoigiaoviec
        {
            get
            {
                return this._nguoigiaoviec;
            }
            set
            {
                this._nguoigiaoviec = value;
            }
        }
        public int nguoigiaohang
        {
            get
            {
                return this._nguoigiaohang;
            }
            set
            {
                this._nguoigiaohang = value;
            }
        }
        public DateTime ngaygiaohang
        {
            get
            {
                return this._ngaygiaohang;
            }
            set
            {
                this._ngaygiaohang = value;
            }
        }
        public int khoxuat
        {
            get
            {
                return this._khoxuat;
            }
            set
            {
                this._khoxuat = value;
            }
        }
        public int khonhap
        {
            get
            {
                return this._khonhap;
            }
            set
            {
                this._khonhap = value;
            }
        }
        public DateTime ngaythu
        {
            get
            {
                return this._ngaythu;
            }
            set
            {
                this._ngaythu = value;
            }
        }
        public string sohd
        {
            get
            {
                return this._sohd;
            }
            set
            {
                this._sohd = value;
            }
        }

        public bool tructiep
        {
            get
            {
                return this._tructiep;
            }
            set
            {
                this._tructiep = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[26];
            paraName[0] = "@id_hd";
            paraName[1] = "@id_ban";
            paraName[2] = "@ngayban";
            paraName[3] = "@nguoiban";
            paraName[4] = "@ghichu";
            paraName[5] = "@trangthai";
            paraName[6] = "@ketkho";
            paraName[7] = "@tongtien";
            paraName[8] = "@khuyenmai";
            paraName[9] = "@conlai";
            paraName[10] = "@datra";
            paraName[11] = "@conno";
            paraName[12] = "@id_kh";
            paraName[13] = "@ngaygiaoviec";
            paraName[14] = "@nguoinhanviec";
            paraName[15] = "@ngayhoanthanh";
            paraName[16] = "@ngayhentra";
            paraName[17] = "@nguoigiaoviec";
            paraName[18] = "@nguoigiaohang";
            paraName[19] = "@ngaygiaohang";
            paraName[20] = "@khoxuat";
            paraName[21] = "@khonhap";
            paraName[22] = "@ngaythu";
            paraName[23] = "@sohd";
            paraName[24] = "@tructiep";
            paraName[25] = "@option";
            object[] paraValue = new object[26];
            paraValue[0] = this._id_hd;
            paraValue[1] = this._id_ban;
            paraValue[2] = this._ngayban;
            paraValue[3] = this._nguoiban;
            paraValue[4] = this._ghichu;
            paraValue[5] = this._trangthai;
            paraValue[6] = this._ketkho;
            paraValue[7] = this._tongtien;
            paraValue[8] = this._khuyenmai;
            paraValue[9] = this._conlai;
            paraValue[10] = this._datra;
            paraValue[11] = this._conno;
            paraValue[12] = this._id_kh;
            paraValue[13] = this._ngaygiaoviec;
            paraValue[14] = this._nguoinhanviec;
            paraValue[15] = this._ngayhoanthanh;
            paraValue[16] = this._ngayhentra;
            paraValue[17] = this._nguoigiaoviec;
            paraValue[18] = this._nguoigiaohang;
            paraValue[19] = this._ngaygiaohang;
            paraValue[20] = this._khoxuat;
            paraValue[21] = this._khonhap;
            paraValue[22] = this._ngaythu;
            paraValue[23] = this._sohd;
            paraValue[24] = this._tructiep;
            paraValue[25] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 26, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }


        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_ERP_HOADON", option);
        }

        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_HOADON", "id_hd = " + this._id_hd);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_hd = Convert.ToInt32(ds.Tables[0].Rows[0]["id_hd"].ToString().Trim());
                this._id_ban = Convert.ToInt32(ds.Tables[0].Rows[0]["id_ban"].ToString().Trim());
                this._ngayban = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngayban"].ToString().Trim());
                this._nguoiban = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoiban"].ToString().Trim());
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                this._trangthai = Convert.ToInt32(ds.Tables[0].Rows[0]["trangthai"].ToString().Trim());
                this._ketkho = Convert.ToInt32(ds.Tables[0].Rows[0]["ketkho"].ToString().Trim());
                this._tongtien = Convert.ToDouble(ds.Tables[0].Rows[0]["tongtien"].ToString().Trim());
                this._khuyenmai = Convert.ToDouble(ds.Tables[0].Rows[0]["khuyenmai"].ToString().Trim());
                this._conlai = Convert.ToDouble(ds.Tables[0].Rows[0]["conlai"].ToString().Trim());
                this._datra = Convert.ToDouble(ds.Tables[0].Rows[0]["datra"].ToString().Trim());
                this._conno = Convert.ToDouble(ds.Tables[0].Rows[0]["conno"].ToString().Trim());
                this._id_kh = Convert.ToInt32(ds.Tables[0].Rows[0]["id_kh"].ToString().Trim());
                this._ngaygiaoviec = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngaygiaoviec"].ToString().Trim());
                this._nguoinhanviec = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoinhanviec"].ToString().Trim());
                this._ngayhoanthanh = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngayhoanthanh"].ToString().Trim());
                this._ngayhentra = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngayhentra"].ToString().Trim());
                this._nguoigiaoviec = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoigiaoviec"].ToString().Trim());
                this._nguoigiaohang = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoigiaohang"].ToString().Trim());
                this._ngaygiaohang = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngaygiaohang"].ToString().Trim());
                this._khoxuat = Convert.ToInt32(ds.Tables[0].Rows[0]["khoxuat"].ToString().Trim());
                this._khonhap = Convert.ToInt32(ds.Tables[0].Rows[0]["khonhap"].ToString().Trim());
                this._ngaythu = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngaythu"].ToString().Trim());
                this._sohd = ds.Tables[0].Rows[0]["sohd"].ToString().Trim();
                this._tructiep = Convert.ToBoolean(ds.Tables[0].Rows[0]["tructiep"].ToString().Trim());

                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public int Get_HD()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_HOADON", "sohd = '" + this._sohd + "'");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_hd = Convert.ToInt32(ds.Tables[0].Rows[0]["id_hd"].ToString().Trim());
                this._id_ban = Convert.ToInt32(ds.Tables[0].Rows[0]["id_ban"].ToString().Trim());
                this._ngayban = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngayban"].ToString().Trim());
                this._nguoiban = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoiban"].ToString().Trim());
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                this._trangthai = Convert.ToInt32(ds.Tables[0].Rows[0]["trangthai"].ToString().Trim());
                this._ketkho = Convert.ToInt32(ds.Tables[0].Rows[0]["ketkho"].ToString().Trim());
                this._tongtien = Convert.ToDouble(ds.Tables[0].Rows[0]["tongtien"].ToString().Trim());
                this._khuyenmai = Convert.ToDouble(ds.Tables[0].Rows[0]["khuyenmai"].ToString().Trim());
                this._conlai = Convert.ToDouble(ds.Tables[0].Rows[0]["conlai"].ToString().Trim());
                this._datra = Convert.ToDouble(ds.Tables[0].Rows[0]["datra"].ToString().Trim());
                this._conno = Convert.ToDouble(ds.Tables[0].Rows[0]["conno"].ToString().Trim());
                this._id_kh = Convert.ToInt32(ds.Tables[0].Rows[0]["id_kh"].ToString().Trim());
                this._ngaygiaoviec = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngaygiaoviec"].ToString().Trim());
                this._nguoinhanviec = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoinhanviec"].ToString().Trim());
                this._ngayhoanthanh = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngayhoanthanh"].ToString().Trim());
                this._ngayhentra = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngayhentra"].ToString().Trim());
                this._nguoigiaoviec = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoigiaoviec"].ToString().Trim());
                this._nguoigiaohang = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoigiaohang"].ToString().Trim());
                this._ngaygiaohang = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngaygiaohang"].ToString().Trim());
                this._khoxuat = Convert.ToInt32(ds.Tables[0].Rows[0]["khoxuat"].ToString().Trim());
                this._khonhap = Convert.ToInt32(ds.Tables[0].Rows[0]["khonhap"].ToString().Trim());
                this._ngaythu = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngaythu"].ToString().Trim());
                this._sohd = ds.Tables[0].Rows[0]["sohd"].ToString().Trim();
                this._tructiep = Convert.ToBoolean(ds.Tables[0].Rows[0]["tructiep"].ToString().Trim());

                return 1;
            }
            catch
            {
                return -1;
            }
        }


        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select cast (0 as bit) as chon, a.sohd, a.id_hd, b.tenkhachhang as tenban, c.tentrangthai, a.ngayban, a.tongtien, a.khuyenmai, a.conlai, a.datra, a.conno, b.dienthoai, d.hoten, a.ngayhoanthanh"
                + " from ERP_HOADON a"
                + " left join ERP_KHACHHANG b on (a.id_kh = b.id_kh)"
                + " left join ERP_HOADON_TRANGTHAI c on (a.trangthai = c.id_trangthai)"
                + " left join HMR_NHANVIEN d on (d.manhanvien = a.nguoinhanviec)"
                + " where a.tructiep = 0 and a.trangthai = " + this._trangthai
                + " order by c.id_trangthai asc";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet Get_List_BHTT()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select a.sohd, a.id_hd, b.tenkhachhang as tenban, c.tentrangthai, a.ngayban, a.tongtien, a.khuyenmai, a.conlai, a.datra, a.conno, b.dienthoai, d.hoten, a.ngayhoanthanh"
                + " from ERP_HOADON a"
                + " left join ERP_KHACHHANG b on (a.id_kh = b.id_kh)"
                + " left join ERP_HOADON_TRANGTHAI c on (a.trangthai = c.id_trangthai)"
                + " left join HMR_NHANVIEN d on (d.manhanvien = a.nguoinhanviec)"
                + " where a.tructiep = 1"
                + " order by c.id_trangthai asc";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet Get_List_Congno()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select a.sohd, a.id_hd, b.tenkhachhang as tenban, c.tentrangthai, a.ngayban, a.tongtien, a.khuyenmai, a.conlai, a.datra, a.conno, b.dienthoai, d.hoten, a.ngayhoanthanh"
                + " from ERP_HOADON a"
                + " left join ERP_KHACHHANG b on (a.id_kh = b.id_kh)"
                + " left join ERP_HOADON_TRANGTHAI c on (a.trangthai = c.id_trangthai)"
                + " left join HMR_NHANVIEN d on (d.manhanvien = a.nguoinhanviec)"
                + " where a.conno > 0 and a.trangthai = 5"
                + " order by c.id_trangthai asc";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }


        public DataSet Get_List_Canhbao(int opt)
        {
            int dd = DateTime.Now.Year*12*30 + DateTime.Now.Month*30 + DateTime.Now.Day;
            string cond = "";
            if (opt == 1)//Canh bao het han May
            {
                cond = " where year(a.ngayhoanthanh)*12*30 + month(a.ngayhoanthanh)*30 + day(a.ngayhoanthanh) <= dd - 2 and a.trangthai = 2";
            }
            else
            {
                cond = " where year(a.ngayhentra)*12*30 + month(a.ngayhentra)*30 + day(a.ngayhentra) <= dd - 2 and a.trangthai not in (4, 5)";
            }
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select a.sohd, a.id_hd, b.tenkhachhang as tenban, c.tentrangthai, a.ngayban, a.tongtien, a.khuyenmai, a.conlai, a.datra, a.conno, b.dienthoai, d.hoten, a.ngayhoanthanh"
                + " from ERP_HOADON a"
                + " left join ERP_KHACHHANG b on (a.id_kh = b.id_kh)"
                + " left join ERP_HOADON_TRANGTHAI c on (a.trangthai = c.id_trangthai)"
                + " left join HMR_NHANVIEN d on (d.manhanvien = a.nguoinhanviec)"
                + cond
                + " order by c.id_trangthai asc";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet Get_List_by_Condition(int i, string condition)
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "";
                if (i == 1)
                {
                    sql = "select cast (0 as bit) as chon, a.sohd, a.id_hd, b.tenkhachhang as tenban, c.tentrangthai, a.ngayban, a.tongtien, a.khuyenmai, a.conlai, a.datra, a.conno, b.dienthoai, d.hoten, a.ngayhoanthanh"
                     + " from ERP_HOADON a"
                     + " left join ERP_KHACHHANG b on (a.id_kh = b.id_kh)"
                     + " left join ERP_HOADON_TRANGTHAI c on (a.trangthai = c.id_trangthai)"
                     + " left join HMR_NHANVIEN d on (d.manhanvien = a.nguoinhanviec)"
                     + " where a.tructiep = 0  and " + condition
                     + " order by c.id_trangthai asc";
                }
                else
                {
                    if (i == 2)
                    {
                        sql = "select cast (0 as bit) as chon, a.sohd, a.id_hd, b.tenkhachhang as tenban, c.tentrangthai, a.ngayban, a.tongtien, a.khuyenmai, a.conlai, a.datra, a.conno, b.dienthoai, d.hoten, a.ngayhoanthanh"
                     + " from ERP_HOADON a"
                     + " left join ERP_KHACHHANG b on (a.id_kh = b.id_kh)"
                     + " left join ERP_HOADON_TRANGTHAI c on (a.trangthai = c.id_trangthai)"
                     + " left join HMR_NHANVIEN d on (d.manhanvien = a.nguoinhanviec)"
                     + " where a.tructiep = 0 and " + condition
                     + " order by c.id_trangthai asc";
                    }
                    else
                    {
                        sql = "select cast (0 as bit) as chon, a.sohd, a.id_hd, b.tenkhachhang as tenban, c.tentrangthai, a.ngayban, a.tongtien, a.khuyenmai, a.conlai, a.datra, a.conno, b.dienthoai, d.hoten, a.ngayhoanthanh"
                     + " from ERP_HOADON a"
                     + " left join ERP_KHACHHANG b on (a.id_kh = b.id_kh)"
                     + " left join ERP_HOADON_TRANGTHAI c on (a.trangthai = c.id_trangthai)"
                     + " left join HMR_NHANVIEN d on (d.manhanvien = a.nguoinhanviec)"
                     + " where a.tructiep = 0 and " + condition
                     + " order by c.id_trangthai asc";
                    }
                }
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet Get_List_by_Condition_BHTT(int i, string condition)
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "";
                if (i == 1)
                {
                    sql = "select a.sohd, a.id_hd, b.tenkhachhang as tenban, c.tentrangthai, a.ngayban, a.tongtien, a.khuyenmai, a.conlai, a.datra, a.conno, b.dienthoai, d.hoten, a.ngayhoanthanh"
                     + " from ERP_HOADON a"
                     + " left join ERP_KHACHHANG b on (a.id_kh = b.id_kh)"
                     + " left join ERP_HOADON_TRANGTHAI c on (a.trangthai = c.id_trangthai)"
                     + " left join HMR_NHANVIEN d on (d.manhanvien = a.nguoinhanviec)"
                     + " where a.tructiep = 1  and " + condition
                     + " order by c.id_trangthai asc";
                }
                else
                {
                    if (i == 2)
                    {
                        sql = "select a.sohd, a.id_hd, b.tenkhachhang as tenban, c.tentrangthai, a.ngayban, a.tongtien, a.khuyenmai, a.conlai, a.datra, a.conno, b.dienthoai, d.hoten, a.ngayhoanthanh"
                     + " from ERP_HOADON a"
                     + " left join ERP_KHACHHANG b on (a.id_kh = b.id_kh)"
                     + " left join ERP_HOADON_TRANGTHAI c on (a.trangthai = c.id_trangthai)"
                     + " left join HMR_NHANVIEN d on (d.manhanvien = a.nguoinhanviec)"
                     + " where a.tructiep = 1 and " + condition
                     + " order by c.id_trangthai asc";
                    }
                    else
                    {
                        sql = "select a.sohd, a.id_hd, b.tenkhachhang as tenban, c.tentrangthai, a.ngayban, a.tongtien, a.khuyenmai, a.conlai, a.datra, a.conno, b.dienthoai, d.hoten, a.ngayhoanthanh"
                     + " from ERP_HOADON a"
                     + " left join ERP_KHACHHANG b on (a.id_kh = b.id_kh)"
                     + " left join ERP_HOADON_TRANGTHAI c on (a.trangthai = c.id_trangthai)"
                     + " left join HMR_NHANVIEN d on (d.manhanvien = a.nguoinhanviec)"
                     + " where a.tructiep = 1 and " + condition
                     + " order by c.id_trangthai asc";
                    }
                }
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet Get_HD_Tinhtien()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select id_hd, id_ban, ngayban, nguoiban, ghichu, trangthai, ketkho, tongtien, khuyenmai, conlai, datra, conno, id_kh"
                + " from ERP_HOADON"
                + " where id_hd = " + this._id_hd;
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }

        public Double Get_Tien_HD()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select sum(thanhtien) as tongtien "
                + " from ERP_CHITIET_HOADON"
                + " where id_hoadon = " + this._id_hd;
                ds = csdl.SelecSQL(sql);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                return Convert.ToDouble(ds.Tables[0].Rows[0]["tongtien"].ToString().Trim());
            }
            catch
            {
                return 0;
            }
        }
    }
}